import java.util.Arrays;

public class Student implements Comparable<Student>{
    public String name;
    public int age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }

    public static void main(String[] args) {

        Student student3 = new Student("wangwu", 32);
        Student student1 = new Student("zhangsan", 52);
        Student student2 = new Student("lishi", 323);
        Student[] students = {student1, student2, student3};
        AgeStudent ageStudent = new AgeStudent();
        Arrays.sort(students,ageStudent);
//        if(student1.compareTo(student1) < 0) {
//            Student temp = student1;
//            student1 = student2;
//            student2 = temp;
//        }

//        System.out.println(student1.toString());
//        System.out.println(student2.toString());
//        System.out.println(student3.toString());
        System.out.println(Arrays.toString(students));

        System.out.println("------------");

        NameStudent nameStudent = new NameStudent();
        Arrays.sort(students, nameStudent);
        System.out.println(Arrays.toString(students));
    }
}
